import request from '../../utils/request'

Page({
    data:{
        userInfo:{},
        recentPlayList:[]
    },
    onShow(){
        // console.log(666);
    },
    onLoad(){
        // console.log('123');
        // console.log(wx.getStorageSync('userInfo'));
        let userInfo = wx.getStorageSync('userInfo')
        if(userInfo){
            this.setData({
                userInfo
            })
            // 获取用户播放记录
            this.getUserRecentPlayList(userInfo.userId)
        }
    },

    async getUserRecentPlayList(uid){
        let result = await request('/user/record',{uid,type:0})
        // console.log(result.data.allData.slice(0,10));
        let index = 0
        let recentPlayList = result.data.allData.slice(0,10).map(item=>{
            item.id = index++
            return item
        })
        this.setData({
            recentPlayList
        })
    },
    toLogin(){
        wx.navigateTo({
          url: '/pages/login/login',
        })
    }
})